package com.lxit.video.util;

import java.util.List;

/**
 * @author 贺长全
 * @time 2018 下午4:00:08
 * @desc 分页工具类;
 */
public class PageUtil<T> {
	private Integer pageIndex; // 当前页
	private Integer pageSize; // 每页显示条数;
	private Integer total = 0; // 总条数; 
	private Integer pageNum; // 总页数; 

	private List<T> rows;

	public PageUtil() {
		super();
	}

	public PageUtil(Integer pageIndex, Integer pageSize, Integer total) {
		super();
		this.pageIndex = pageIndex;
		this.pageSize = pageSize;
		this.total = total;
		init();
	}

	private void init() {
		pageNum = (total % pageSize == 0) ? total / pageSize : total / pageSize + 1;
		if (pageIndex < 1) {
			pageIndex = 1;
		} else if (pageIndex > pageNum) {
			pageIndex = pageNum;
		}
	}

	public List<T> getRows() {
		return rows;
	}

	public void setRows(List<T> rows) {
		this.rows = rows;
	}

	public Integer getPageIndex() {
		return pageIndex;
	}

	public void setPageIndex(Integer pageIndex) {
		this.pageIndex = pageIndex;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public Integer getTotal() {
		return total;
	}

	public void setTotal(Integer total) {
		this.total = total;
	}

	public Integer getPageNum() {
		return pageNum;
	}

	public void setPageNum(Integer pageNum) {
		this.pageNum = pageNum;
	}
}